<template>
	<!-- 申请退款 -->
	<view class="form-container">
		<nt-order-detail :orderInfo="commonForm.orderInfo"></nt-order-detail>
		<nt-card label="回收配件">
			
		
		<view class="back-list">
			<view class="back-list__item">
				<view class="back-list__item--type weight">配件类型</view>
				<view class="back-list__item--name weight">配件名称</view>
				<view class="back-list__item--number weight">配件数量</view>
				<view class="back-list__item--price weight">配件金额</view>
				<view class="back-list__item--btn weight"></view>
			</view>
			<view 
				class="back-list__item"
				v-for="(it, index) in backPartsList" 
				:key="index"
			>
				<view class="back-list__item--type" @tap="selectBackParts(index)">
					{{ it.name || "请选择" }} <text class="iconfont">&#xe6bb;</text>
				</view>
				<view class="back-list__item--name">
					<!-- {{ it.customName || "名称" }} -->
					<u--input v-model="it.customName" placeholder="名称" inputAlign="center"></u--input>
				</view>
				<view class="back-list__item--number">
					<u--input v-model="it.quantity" placeholder="数量" inputAlign="center"></u--input>
				</view>
				<view class="back-list__item--price">
					<u--input v-model="it.price" placeholder="价格" inputAlign="center"></u--input>
				</view>
				<view class="back-list__item--btn">
					<view class="back-list__item--btn-b" @tap="addBackParts(index)" v-if="index == 0">+</view>
					<view class="back-list__item--btn-r" @tap="deleteBackParts(index)" v-else>-</view>
				</view>
			</view>
		</view>
			
			<nt-button text="提交" @tap="submit"></nt-button>
		</nt-card>
		
	</view>
</template>

<script>
import { applyRefund } from "@/api"
export default {
	data(){
		return {
			formData: {
				images: []
			},
			backPartsList: [
				{ value: "", name: "", quantity: 1, price: "" }
			],
			loading: false
		}
	},
	inject: ["commonForm"],
	methods: {
		successUpload(e){
			console.log(e,'图片上传')
			this.formData.images = e
		},
		submit(){
			const { remarks, money, images } = this.formData; 
			if(!money) return this.toast("请输入退款金额")
			if(!remarks) return this.toast("请填写退款内容")
			if(!images.length) return this.toast("请上传退款图片")
			if(this.loading) return
			applyRefund({
				realorder_id: this.commonForm.options.id,
				remarks,
				money,
				images: images.map(item => item.url)
			}).then(res => {
				const { code, data, msg } = res;
				if(code !== 1) return this.toast(msg)
				this.toast("退款申请成功")
				setTimeout(() => this.back(), 1000)
			}).finally(() => {
				this.loading = false
			})
		}
	}
}
</script>

<style scoped lang="scss">
@import "./style.scss";
</style>
